﻿using System;
using ExtensionMethods;

namespace 扩展方法2
{
    class Program
    {
        static void StringTest()
        {
            String str = "a";

            bool b = str.IsEmpty();
            if(b)
            {
                Console.WriteLine("空");
            }
            else
            {
                Console.WriteLine("有值");
            }

            str = "1234";
            long lg = str.ExtractInt64();
            Console.WriteLine(lg);

            str = "abc;bcd;afg";
            string[] sts = str.Split(';');
            foreach (var item in sts)
            {
                Console.WriteLine(item);
            }

            str = String.Join(",", sts);
            Console.WriteLine(str);

            str = "abc";
            str = str.Repeat(5);
            Console.WriteLine(str);

            str = " abc";
            str = str.LeftSafe(2); // 从左往右截取字符串
            Console.WriteLine(str);

            str = " abcde";
            str = str.Left(3);
            Console.WriteLine(str);

            str = "abc1234bcd34";
            double db = str.GetNumericValue(3);
            Console.WriteLine(db);


            str = "abc";
            str = str.Concat("123");
            str = str.ConcatWith(sts);

            Console.WriteLine(str);
            

            str.ToByteArray();


            Console.WriteLine(str.ToDirectoryInfo());
        }







        static void Main(string[] args)
        {
            //string str = "hello world";
            //int count = str.WordCount();
            //Console.WriteLine(count);
            //Console.WriteLine("Hello World!");

            StringTest();

            Console.ReadKey();
        }
    }
}


namespace ExtensionMethods
{
    public static class MyExtensions
    {
        public static int WordCount(this string str)
        {
            return str.Split(new char[] { ' ', '.', '?' },
                             StringSplitOptions.RemoveEmptyEntries).Length;
        }
    }
}